// 月份天数总集合(31天)
const monthlyDaysCollection = []

/**
 * 生成月份所有天数的集合（31条数据）
 */
function addDaysCollection() {
  let i = 1
  while (i <= 31) {
    monthlyDaysCollection.push({
      label: i + '号',
      value: i
    })
    i++
  }
}

addDaysCollection()


// 月日级联选择器
const monthDayMap = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
const monthDayCascade = []

function addMonthDayCascade(array) {
  let i = 0
  while (i < array.length) {
    let children = new Array(array[i]).fill(null)
    children = children.map((i, idx) => ({
      label: idx + 1 + '号',
      value: idx + 1
    }))
    monthDayCascade.push({
      label: i + 1 + '月',
      value: i + 1,
      children
    })
    i++
  }
}

addMonthDayCascade(monthDayMap)

// 第几季度对应包含的月份
const quarterMonthMap = {
  1: [1, 2, 3],
  2: [4, 5, 6],
  3: [7, 8, 9],
  4: [10, 11, 12],
}

/**
 * 根据当前年、季度以及季度下的第几个月生成YYYY-M的形式的字符串
 * @param year 当前年
 * @param quarter 第几季度
 * @param nth 季度第几个月
 * @returns {string} 'YYYY-M'形式的字符串
 */
function formatDateByQuarter(year, quarter, nth) {
  return `${year}-${quarterMonthMap[quarter][nth - 1]}`
}

export {
  monthlyDaysCollection,
  monthDayCascade,
  formatDateByQuarter
}
